package com.example.testdemo.default_recycler_view_adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.testdemo.R;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;

/**
 * Created by 颜 on 04.02.002.
 * 原生适配器
 */

public class DefaultAdapter extends RecyclerView.Adapter<MyViewHolder>{

    private Context context;
    private ArrayList<Integer> data;

    public DefaultAdapter(Context context){
        this.context = context;
        data = new ArrayList<>();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_default_adapter,null);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        ImageView imageView = holder.getImageView();
        int imgUrl = data.get(position);
        imageView.setImageResource(imgUrl);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }


    public void setData(ArrayList<Integer> netImage) {
        data.addAll(netImage);
        notifyDataSetChanged();
    }
}
